﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter21.Models.SynchronizationSamples
{
    public class ThreadSynchronized
    {
        public virtual bool IsSynchronized
        {
            get { return false; }
        }

        public virtual void DoThis()
        {

        }
        public virtual void DoThat()
        {

        }

        private class ThreadSynchronizedInternalClass : ThreadSynchronized
        {
            private object syncBoot = new object();
            private ThreadSynchronized d;

            public ThreadSynchronizedInternalClass(ThreadSynchronized d)
            {
                this.d = d;
            }

            public override bool IsSynchronized
            {
                get { return true; }
            }

            public override void DoThis()
            {
                lock (syncBoot)
                {
                    d.DoThis();
                }
            }
            public override void DoThat()
            {
                lock (syncBoot)
                {
                    d.DoThat();
                }
            }
        }
    }
}
